<{include file="public/header.html"}>
		<div class="xinsu-right">
			<div class="xinsu-right-content">
				<div class="xinsu-data-content">
					<div class="xinsu-title">
						<span class="layui-breadcrumb">
							<a><cite>当前位置</cite></a>
							<a><cite>用户持仓</cite></a>
						</span>
					</div>
					<form class="layui-form xinsu-form" action="" method="get">
						<div class="layui-form-item">
						    <div class="layui-inline">
						      	<label class="layui-form-label xinsu-form-label">账号类型</label>
						      	<div class="layui-input-inline xinsu-input-inline">
							        <select name="demo_account">
										<option value="2">全部</option>
										<option value="0" <{if $demo_account == 0}>selected<{/if}>>正式</option>
										<option value="1" <{if $demo_account == 1}>selected<{/if}>>试玩</option>
									</select>
						        </div>
						    </div>
							<div class="layui-inline">
						      	<label class="layui-form-label xinsu-form-label">股票类型</label>
						      	<div class="layui-input-inline xinsu-input-inline">
							        <select name="bull_type">
										<option value="0">全部</option>
										<option value="1" <{if $bull_type == 1}>selected<{/if}>>融资</option>
										<option value="2" <{if $bull_type == 2}>selected<{/if}>>融券</option>
									</select>
						        </div>
						    </div>
							
							 <div class="layui-inline">
						      	<label class="layui-form-label xinsu-form-label">查询日期</label>
						      	<div class="layui-input-inline">
						        	<input type="text" name="start_time" placeholder="开始日期" autocomplete="off" class="layui-input" onclick="layui.laydate({elem: this})" value="<{if $start_time != '0'}><{$start_time}><{/if}>">
						      	</div>
						      	<label class="layui-form-label xinsu-form-label2">至</label>
						      	<div class="layui-input-inline">
						        	<input type="text" name="end_time" placeholder="结束日期" autocomplete="off" class="layui-input" onclick="layui.laydate({elem: this})" value="<{if $end_time != '0'}><{$end_time}><{/if}>">
						      	</div>
						    </div>
						    <div class="layui-inline">
						    	<label class="layui-form-label xinsu-form-label">搜索条件</label>
								<div class="layui-input-block xinsu-input-block2">
								    <input type="text" name="username" value="<{if $username != '0'}><{urldecode($username)}><{/if}>" class="layui-input" placeholder="帐号 / 真实姓名"/>
								</div>
						    </div>
						   <button class="layui-btn xinsu-btn">查询</button>
							<span>记录总数：共 <{$total}> 条</span>
						</div>
					</form>
					<div class="layui-form xinsu-form">
						<table class="layui-table">
							<thead>
								<tr>
									<th>ID</th>
									<th>帐号</th>
									<th>代码/名称</th>
									<th>建仓时间</th>
									<th>买入价</th>
									<th>当前价</th>
									<th>股票类型</th>
									<th>持仓数量</th>
									<th>持仓金额</th>
									<th>留仓费/天</th>
									<th>手续费</th>
									<th>管理费</th>
									<th>浮盈</th>
									<th>操作</th>
								</tr> 
							</thead>
							<tbody>
								<{if empty($list) == false}>
								<{foreach $list as $val}>
									<tr id="xinsu-stock-<{$val.id}>" class="xinsu-stock-status" data="<{$val.id}>">
									<td><{$val.id}></td>
									<td><a class="xinsu-fontcolor-blue xinsu-user" href="javascript:;" data="<{$val.uid}>"><{$val.username}></a></td>
									<td><a class="xinsu-fontcolor-blue xinsu-stock-figure" href="javascript:;" data="<{$val.stock}>"><{$val.stock}>/<{$val.stock_name}></a></td>
									<td class="xinsu-fontcolor-green"><{date("Y-m-d H:i:s", $val["bull_time"])}></td>
									<td><{$val.bull_price}></td>
									<td id="xinsu-stock-price-<{$val.id}>">--</td>
									<{if $val.bull_type == 1}>
									<td class="xinsu-fontcolor-red">融资↑</td>
									<{else}>
									<td class="xinsu-fontcolor-green">融券↓</td>
									<{/if}>
									<td><{$val.bull_num - $val.sell_num}></td>
									<td class="xinsu-fontcolor-red"><{number_format($val.bull_money, 2)}></td>
									<td id="xinsu-stock-save-<{$val.id}>">--</td>
									<td><{$val.bull_cost_money}></td>
									<td id="xinsu-stock-mange-<{$val.id}>">--</td>
									<td id="xinsu-stock-gain-<{$val.id}>">--</td>
									<td>
										<a class="xinsu-fontcolor-blue xinsu-amend xinsu-block-sell" id="xinsu-stock-manger-<{$val.id}>" href="javascript:;" data="<{$val.id}>" data-num="共<{$val.bull_num}>（股） 已委托 <{$val.bull_num - $val.can_sell_num - $val.sell_num}>（股） 可卖：<{$val.can_sell_num}>（股）" data-stock='<{$val.stock}>' data-cannum="<{$val.can_sell_num}>" data-stockname='<{$val.stock_name}>' data-bulltime="<{date('Y-m-d H:i:s', $val['bull_time'])}>" data-bulltype="<{$val.bull_type}>" data-bullprice="<{$val.bull_price}>"></a>
									</td>
								</tr>
								<{/foreach}>
								<tr>
						        	<td colspan="9" style="text-align:right">合计：</td>
						        	<td id="xinsu-bull-money" class="xinsu-fontcolor-red">--</td>
						        	<td colspan="3" style="text-align:right">总盈亏：</td>
						        	<td id="xinsu-total-gain">--</td>
						        	<td></td>
						        </tr>
								<{else}>
								<tr>
									<td colspan="14">暂无数据</td>
								</tr>
								<{/if}>
							</tbody>
						</table>
					</div>
					<div class="xinsu-page">
						<div class="xinsu-show">
							<{$page}>
						</div>
						<div class="xinsu-clear"></div>
					</div>
				</div>
			</div>
		</div>
		<script>
			$(function(){
				get_stock();
			})
			var stock = 0;
			function get_stock() {
				if (stock >= 0 && system_holiday == 0) {
					var url = "/stock/ajax_get_bull";
					var data = "";
					$(".xinsu-stock-status").each(function(){
						var tmp = $(this).attr("data");
						if (tmp != undefined) {
							data += "," + tmp;
						}
					})
					http_request_post(url, {data:data}, function(result) {
						if (result.status == 1) {
							var res = result.data;
							var total_gain = bull_money = 0;
							$.each(res, function(key, val){
								$("#xinsu-stock-price-" + key).html(val["price"]);//当前价格
								$("#xinsu-stock-save-" + key).html(val["save"]);//留仓天数
								$("#xinsu-stock-mange-" + key).html(val["manage_money"]);//留仓天数
								
								//判断盈亏
								if (val["total_gain"] > 0) {
									$("#xinsu-stock-gain-" + key).addClass("xinsu-fontcolor-red").removeClass("xinsu-fontcolor-green");
								} else {
									$("#xinsu-stock-gain-" + key).addClass("xinsu-fontcolor-green").removeClass("xinsu-fontcolor-red");
								}
								$("#xinsu-stock-gain-" + key).html(val["total_gain"]);
								
								//管理操作
								if (val.can_sell == 1) {
									$("#xinsu-stock-manger-" + key).html("除权除息平仓");
								} else {
									$("#xinsu-stock-manger-" + key).html("强制平仓");
								}
								
								//计算盈亏
								total_gain += val["total_gain"];
								bull_money += val["bull_money"];
							})
							
							//合计
							total_gain = Math.round(total_gain * 100) / 100;
							if (total_gain >= 0) {
								$("#xinsu-total-gain").addClass("xinsu-fontcolor-red").removeClass("xinsu-fontcolor-green");
							} else {
								$("#xinsu-total-gain").addClass("xinsu-fontcolor-green").removeClass("xinsu-fontcolor-red");
							}
							$("#xinsu-total-gain").html("￥" + total_gain);
							$("#xinsu-bull-money").html("￥" + bull_money);
						} else {
							stock = -1;
						}
					});
				}
				//定时
				stock = setTimeout("get_stock();", 1500);
			}

			//强制平仓
			$(".xinsu-block-sell").click(function(){
				//设置参数
				var id = $(this).attr("data");
				var num = $(this).attr("data-num");
				var stock = $(this).attr("data-stock");
				var stock_name = $(this).attr("data-stockname");
				var can_sell_num = $(this).attr("data-cannum");
				var bull_time = $(this).attr("data-bulltime");
				var bull_price = $(this).attr("data-bullprice");
				var bull_type = $(this).attr("data-bulltype");
				var price = $("#xinsu-stock-price-" + id).html();
				if (bull_type == "融资") {
					bull_type = '<td style="text-align: left;" class="xinsu-fontcolor-green">'+bull_type+'</td>';
				} else {
					bull_type = '<td style="text-align: left;" class="xinsu-fontcolor-red">'+bull_type+'</td>';
				}
				
				//弹出卖出
				layer.open({ 
					type: 1,
					title: '订单号：'+id+' 强制股票平仓',
					area: ['550px', '440px'],
					btn:['确定', '取消'],
					shadeClose: true, //点击遮罩关闭
					content: '<div style="padding:10px 40px 0 40px; line-height:36px; font-size:14px;"><form class="layui-form xinsu-form"><table class="layui-table xinsu-table"><tbody><tr><td>股票名称：</td><td style="text-align: left;">'+stock_name+'</td></tr><tr><td>股票代码：</td><td style="text-align: left;" class="xinsu-fontcolor-green">'+stock+'</td></tr><tr><td>持仓时间：</td><td style="text-align: left;">'+bull_time+'</td></tr><tr><td>持仓数量：</td><td style="text-align: left;">'+num+'</td></tr><tr><td>股票类型：</td>'+bull_type+'</tr><tr><td>买入价格：</td><td style="text-align: left;" class="xinsu-fontcolor-red">'+bull_price+' 元/股 </td></tr><tr><td>当前价格：</td><td style="text-align: left;" class="xinsu-fontcolor-green">'+price+' 元/股</td></tr><tr><td>平仓数量：</td><td><input style="border:solid 1px #efefef; width:80%;" type="text" name="num" id="num" class="layui-input" value="'+can_sell_num+'" placeholder="最大卖出数量'+can_sell_num+'股" /></td></tr></tbody></table></form></div>',
					yes:function(index, layers){
						var can_num = $("#num").val();
						layer.closeAll();
						http_request_post("/stock/ajax_set_sell", {id:id, num:can_num, token:token}, function(result){
							layer.msg(result.msg, {icon:1, time:800}, function(){
								location.reload();
							});
						});
					}
					
				});
			})
		</script>
<{include file="public/footer.html"}>
